Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


Using the QUOTER function to assemble a query

Notice the use of the single quotation marks embedded in the strings that are assembled to build up the FOR EACH statement:

hQuery:QUERY-PREPARE("FOR EACH Order WHERE SalesRep = '" +  
                      cSalesRep + "', FIRST Customer OF Order"). 

The first literal ends with a single quote mark, which precedes the SalesRep initials. This, in turn, is followed by another literal that begins with a single quote mark to balance the first one. This kind of assemblage of strings with and without quote marks can get very tricky and lead to code that is hard to read and programming errors that are hard to identify. Here, for example, you need to remember not only to put the quote marks into the statement before and after the cSalesRep value, but also to use single quotes so that they don’t interfere with the use of double-quotes around the literals themselves. You could reverse these and use double quotes inside single quotes, but either way you need to be sure to balance them and embed them properly.

Progress provides a helpful function to assist you in assembling these kinds of strings, the QUOTER function. If you insert values of any data type into a string, such as this QUERY-PREPARE as arguments to the QUOTER function, Progress assembles the string properly so that you don’t need to worry about where the embedded quote marks go. For instance, here’s an alternative version of the QUERY-PREPARE method that uses QUOTER:

hQuery:QUERY-PREPARE("FOR EACH Order WHERE SalesRep = " +  
                     QUOTER(cSalesRep) + ", FIRST Customer OF Order"). 

In Figure 19–7, Progress inserts quote marks around the SalesRep initials for you.

Figure 19–7: Example QUOTER function message

You can use QUOTER to avoid parsing errors for numeric values as well as string values. For example, DECIMAL formats in parts of the world outside the United States typically reverse the meaning of the decimal point or period/full stop (.) and comma (,) characters. If you use QUOTER on all such values, Progress assembles a query string that compiles properly without causing confusion to the syntax analyzer, which must interpret whether the “.” character is a decimal point, a separator between thousands in a numeric value, or the end of a statement.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095